<template>
  <div>
    <el-table v-loading="loading" :data="showList" stripe>
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="content" label="内容"></el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <img :src="scope.row.img" alt height="50" />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="onDel(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 确认删除对话框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span>确定删除该项吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="doDel">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { fetchList, del} from '@/api/shows.js'
import scroll from '@/utils/scroll.js'
export default {
  data() {
    return {
      showList: [],
      loading: false,
      dialogVisible: false,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      fetchList().then((res) => {
        console.log(res.data)
        const data = res.data
        let _showList = []
        for (let i = 0, len = data.length; i < len; i++) {
          _showList.push(JSON.parse(data[i]))
        }
        this.showList = this.showList.concat(_showList)
        this.loading = false
      })
    },
  
    onDel(row) {
      this.show = row
      this.dialogVisible = true
    },
    doDel() {
      this.loading = true
      del(this.show).then((res) => {
        this.loading = false
        this.dialogVisible = false
        this.getList()
        this.$message({
          message: '删除成功',
          type: 'success',
        })
      })
    },
  },

}
</script>
<style>
</style>